<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            治具与滑橇绑定
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">滑橇编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入滑橇编码" id="skiddingCode" value="">
                    </div>
                </div>
            </li>
            <div class="aui-btn aui-btn-info aui-btn-block" style="margin:2% 0 ;" onclick="search()">查询绑定关系</div>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">治具编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入治具编码" id="fixtureCode" value="">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">层数</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入层数" id="level" value="">
                    </div>
                </div>
            </li>
            <div class="aui-btn aui-btn-info aui-btn-block" style="margin:2% 0 ;" onclick="save()">绑定治具</div>
        </ul>

        <ul class="ui-selectee" id="tbodyHtml">

        </ul>

        <p></p>
        <p></p>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>


    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">



    var scanRule = ""; //条码解析规则
    var arrSave = [];
    var message = "";

    //初始化查询仓库下拉框
    apiready = function () {

    }


    //保存按钮
    function save() {
        var skiddingCode = $("#skiddingCode").val();
        var fixtureCode = $("#fixtureCode").val();
        var level = $("#level").val();
        
        if (fixtureCode == "" || fixtureCode == null || fixtureCode == undefined) {
            api.toast({
                msg: '治具编码不能为空',
                duration: 3000
            });
            return;
        }
        if (level == "" || level == null || level == undefined) {
            api.toast({
                msg: '层级不能为空',
                duration: 3000
            });
            return;
        }
        
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/skiddingCodeBind";
        var data = {
            values: {
                skiddingCode: skiddingCode,
                fixtureCode: fixtureCode,
                level: level, 
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    }); //清空表单
                    $("#message").val("提示信息: 绑定成功");
                    search()
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {

                api.hideProgress();
                $("#message").val("");
                alert(JSON.stringify(err));
            }
        });
    }

    function search() {

        var skiddingCode = $("#skiddingCode").val()
        if (skiddingCode == "" || skiddingCode == null || skiddingCode == undefined) {
            api.toast({
                msg: '滑橇号不能为空',
                duration: 3000
            });
            return;
        }
        api.showProgress({
            title: '查询中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getSkiddingCodeBind";
        var data = {
            values: {
                un: un,
                skiddingCode: skiddingCode
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();

                    console.log(JSON.stringify(myobj.list));
                    setTable(myobj.list);
                } else if (myobj.code == '1') {
                    $("#message").val("");
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                $("#message").val("");
                alert(JSON.stringify(err));
            }
        });
    }

    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += "<li class='sortable ui-selectee ui-sortable'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee'>";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>滑橇编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].skiddingCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>滑橇名称</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].skiddingName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>治具编码</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].fixtureCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>治具名称</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].fixtureName + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>层数</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].level + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'></div>";
            html += "<div class='aui-list-item-inner ui-selectee'></div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:red;color:#f5f5f5;' onclick='remove(\"" + list[i].sysid + "\",\"" + list[i].skiddingCode + "\");'>解绑</div>";
            html += "</div>";
            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };


    function remove(sysid,skiddingCode) {
        api.showProgress({
            title: '解绑中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/skiddingCodeUnBind";
        var data = {
            values: {
                un: un,
                skiddingCode: skiddingCode,
                sysid: sysid
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "解绑成功",
                        duration: 3000
                    });

                    search()
                } else if (myobj.code == '1') {
                    $("#message").val("");
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                $("#message").val("");
                alert(JSON.stringify(err));
            }
        });


    };




    //箱号监听回车事件
    $("#ext03").on('keypress', function (e) { //#keyword为input文本框
        if (!clickThrottle()) {
            return;
        }
        var keycode = e.keyCode;
        var ext03 = $(this).val();
        $("#ext03").val(ext03);
        if (keycode == '13') {
            if (ext03 != null && ext03 != "" && ext03 != undefined) {
                console.log(ext03);
                getRsExt03(ext03);
            }
        }
    });

    //箱号监听回车事件
    $("#rs_barcode_gid").on('keypress', function (e) { //#keyword为input文本框
        if (!clickThrottle()) {
            $("#rs_barcode_gid").val("");
            return;
        }
        var keycode = e.keyCode;
        var rs_barcode_gid = $(this).val();
        $("#rs_barcode_gid").val("");
        if (keycode == '13') {
            if (rs_barcode_gid != null && rs_barcode_gid != "" && rs_barcode_gid != undefined) {
                console.log(rs_barcode_gid);
                save(rs_barcode_gid);
            }
        }
    });

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>